﻿<Serializable()> _
Public Class Shifting
    Private _WharfID As String
    Private _ShiftingID As String
    Private _DateStart As String
    Private _TimeStart As String
    Private _DateEnd As String
    Private _TimeEnd As String
    Private _Remark As String
    Private _Note As String
    Private _PortType As String
    Private _Product As Product()
    Private _WharfName As String
    Public Property ShiftingID() As String
        Get
            Return _ShiftingID
        End Get
        Set(ByVal value As String)
            _ShiftingID = value
        End Set
    End Property
    Public Property WharfID() As String
        Get
            Return _WharfID
        End Get
        Set(ByVal value As String)
            _WharfID = value
        End Set
    End Property
    Public Property DateStart() As String
        Get
            Return _DateStart
        End Get
        Set(ByVal value As String)
            _DateStart = value
        End Set
    End Property
    Public Property TimeStart() As String
        Get
            Return _TimeStart
        End Get
        Set(ByVal value As String)
            _TimeStart = value
        End Set
    End Property
    Public Property DateEnd() As String
        Get
            Return _DateEnd
        End Get
        Set(ByVal value As String)
            _DateEnd = value
        End Set
    End Property
    Public Property TimeEnd() As String
        Get
            Return _TimeEnd
        End Get
        Set(ByVal value As String)
            _TimeEnd = value
        End Set
    End Property
    Public Property Remark() As String
        Get
            Return _Remark
        End Get
        Set(ByVal value As String)
            _Remark = value
        End Set
    End Property
    Public Property Note() As String
        Get
            Return _Note
        End Get
        Set(ByVal value As String)
            _Note = value
        End Set
    End Property
    Public Property PortType() As String
        Get
            Return _PortType
        End Get
        Set(ByVal value As String)
            _PortType = value
        End Set
    End Property
    Public Property Product() As Product()
        Get
            Return _Product
        End Get
        Set(ByVal value As Product())
            _Product = value
        End Set
    End Property
    Public Property WharfName() As String
        Get
            Return _WharfName
        End Get
        Set(ByVal value As String)
            _WharfName = value
        End Set
    End Property
    Public Function GetShifting(ByVal Booking_no As String) As List(Of Shifting)
        Dim shiftingList As New List(Of Shifting)
        Dim db As New DB_Class()
        db.queryString = "select * from Booking_Shifting bs"
        db.queryString &= " left outer join Wharf w on bs.BookingWharf=w.BookingWharf"
        db.queryString &= " where Booking_no='" & Booking_no & "'"
        Dim dtShifting As DataTable = db.getTable("bookingShift")
        If (dtShifting.Rows.Count > 0) Then
            For Each drShifting As DataRow In dtShifting.Rows
                Dim shiftingItem As New Shifting()
                shiftingItem.ShiftingID = drShifting("Shifting_ID").ToString()
                shiftingItem.WharfName = drShifting("Wharf").ToString()

                Dim productList As New List(Of Product)
                db.queryString = "select * from Booking_Shifting_Product bsp"
                db.queryString &= " left outer join Booking_Product bp on (bsp.Product_no=bp.Product_no and bp.Booking_no='" & Booking_no & "')"
                db.queryString &= " where Shifting_ID = '" & drShifting("Shifting_ID") & "'"

                Dim dtProductShifting As DataTable = db.getTable("prodShifting")
                If (dtProductShifting.Rows.Count > 0) Then
                    For Each drProductShifting As DataRow In dtProductShifting.Rows
                        Dim productItem As New Product()
                        productItem.ProductID = drProductShifting("Product_no").ToString()
                        productItem.ProductName = drProductShifting("Product_name").ToString()
                        productItem.ProductVolume = drProductShifting("Product_volume").ToString()
                        productItem.ProductUnit = drProductShifting("Product_Unit").ToString()
                        productList.Add(productItem)
                    Next
                End If
                shiftingItem.Product = productList.ToArray()
                shiftingList.Add(shiftingItem)
            Next

        End If
        Return shiftingList
    End Function
End Class
